/*
 * Project Name: cms_framework
 * File Name: BaseAjaxAction.java
 * Copyright: ZKTeco Corporation 2015
 * Description: TODO 请在此处添加对本文件的描述
 * Creator: Administrator
 * Create Date: 2015年1月27日 下午12:01:43
 */
package com.shishuo.cms.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.support.RequestContext;

import com.shishuo.cms.entity.vo.JsonVo;
import com.shishuo.cms.exception.ValidateException;

public class BaseAjaxAction
{
	protected final Logger logger = Logger.getLogger(this.getClass());
	
	protected HttpServletRequest request;

	protected HttpServletResponse response;

	protected HttpSession session;

	@ModelAttribute
	public void setReqAndRes(HttpServletRequest request, HttpServletResponse response){
		this.request = request;
		this.response = response;
		this.session = request.getSession();
	}
	
	protected <T> void validate(JsonVo<T> json) throws ValidateException {
		if (json.getErrors().size() > 0) {
			json.setResult(false);
			throw new ValidateException("有错误发生");
		} else {
			json.setResult(true);
		}
	}
	public boolean validateJsonIsError(JsonVo<String> json)  {
		if (json.getErrors().size() > 0) {
			return true;
		} 
		return false;
	}
	
	/*
	 *获取国际化内容 
	 * */
	public String getMsgByMsgKey(String msgKey) {
		RequestContext requestContext = new RequestContext(request);
		return requestContext.getMessage(msgKey);
	}
	
	
}
